
//工作联系 操作区

import util from "../../common/js/util.js";
var app = getApp();
const base_postpone_btn_list = {//延期审核
  submit_btn_show: false,//提交
  agree_btn_show: false,//同意
  veto_btn_show: false,//否决
  comment_show: false, //延期详情评论内容展示
  cancel_left_btn_show: false,//左边的取消按钮 这两个按钮都是同一个功能 仅仅为了美观
  cancel_reight_btn_show: false,//右边边的取消按钮
}
let baseApprover = {
  tagValue: "",
  Position: "",
  Approver: "",
  ApproverUserCnName: "",
  NOTE: ""
}
const baseImgList = [
  {
    src: "/common/img/11.png",
    checked: false,
    score: "60以下",
    no: 11
  },
  {
    src: "/common/img/12.png",
    checked: false,
    score: "60-70",
    no: 12
  },
  {
    src: "/common/img/13.png",
    checked: false,
    score: "70-80",
    no: 13
  },
  {
    src: "/common/img/14.png",
    score: "80-90",
    checked: false,
    no: 14
  },
  {
    src: "/common/img/15.png",
    score: "90-100",
    checked: false,
    no: 15
  }
]
Component({
  mixins: [],
  data: {
    user_btn_show: false,//当前审批人 审批 (非管理员)
    show_admin_btn: false,
    showComment: false,//管理员审批 弹层
    showComment2: false,//评论内容 弹层
    typeName: "",//gradually 逐级  examination 会同
    showMore: false,//更多 弹层
    showAdjourn: false,//延期 弹层

    searchList: {},
    SearchList: {},
    COMMENT: "",
    STATUS: "",
    postpone_btn_list: JSON.parse(JSON.stringify(base_postpone_btn_list)),

    btn_list: [
      //{btn_show:true,func:"taskOpen",name:"递进任务",clazz:"background-blue",parameter:""}
    ],
    objectArray: [
      {
        id: 0,
        name: '在我之前',
        tag: "Left"
      },
      {
        id: 1,
        name: '在我之后',
        tag: "Right"
      },
    ],
    arrIndex: 0,
    // items: [
    //   { name: '1', value: '替当前审批人，环节进入下一个审批人审批', checked: true },
    //   { name: '2', value: '全部审批通过' },
    //   { name: '3', value: '驳回审批' },
    //   { name: '4', value: '撤回' }
    // ],
    redio_value: "1",
    showScore: false,
    Approver: JSON.parse(JSON.stringify(baseApprover)),
    title: "",
    adjournTitle: "",
    adjournCommonList:[],//延期申请评论列表
    status: "",
    title:"",
    ceteImgList1: util.copy(baseImgList),
    ceteImgList3: util.copy(baseImgList),
    ceteImgList5: util.copy(baseImgList),
    score1: "",
    score2: "",
    score3: "",
    showVetoYanqi:false

  },
  props: {
    searchList: Object,
    onReloadFn: function onReloadFn(e) { }
  },

  didMount() {
    //  console.log(app.prototype.$userList);
  },
  didUpdate() { },
  didUnmount() { },
  methods: {
    imgClick(e) {
      let index = e.currentTarget.dataset.index;
      let type = e.currentTarget.dataset.type;
      let ceteImgList = util.copy(baseImgList);
      let score = "";
      // if (type == 1) {
      //   ceteImgList = this.data.ceteImgList1;
      // } else {
      //   ceteImgList = this.data.ceteImgList2;
      // }
      for (let a = 0; a < ceteImgList.length; a++) {
        if (a != index) {
          ceteImgList[a].checked = false;
          ceteImgList[a].src = `/common/img/${ceteImgList[a].no}.png`;
        }
      }
      ceteImgList[index].checked = true;
      let src = ceteImgList[index].src;
      if (ceteImgList[index].checked) {
        score = ceteImgList[index].score;
        src = `/common/img/${ceteImgList[index].no}_hover.png`;
      } else {
        src = `/common/img/${ceteImgList[index].no}.png`;
      }
      ceteImgList[index].src = src;
      let value = this.getImgValue(index);
      this.setData({
        [`score${type}`]: score,
        [`ceteImgList${type}`]: ceteImgList,
      });
      switch (parseInt(type)) {
        case 1:
          this.setData({
            "searchList.EVALUATE1": value
          });
          break;
        case 3:
          this.setData({
            "searchList.EVALUATE3": value
          });
          break;
        case 5:
          this.setData({
            "searchList.EVALUATE5": value
          });
          break;                  
        default:
          break;
      }
      //console.log("---searchList:",this.data.searchList);
    },
    getImgValue(index) {
      let EVALUATE = "";
      switch (index) {
        case 0:
          EVALUATE = 11;
          break;
        case 1:
          EVALUATE = 12;
          break;
        case 2:
          EVALUATE = 13;
          break;
        case 3:
          EVALUATE = 14;
          break;
        case 4:
          EVALUATE = 15;
          break;
      }
      return EVALUATE;
    },
    onScoreSubmit() {

      /**
        4                            8                                   10
      提请人->经办人->经办领导[经办领导评价经办人]->提请人【提请人评价经办人|提请人评价经办领导】
      
      EVALUATE1 提请人评价经办人
      EVALUATE3 提请人评价经办领导
      EVALUATE5 经办领导评价经办人 

      */

      
      if(this.data.status==10){
        if(util.isEmpty(this.data.searchList.EVALUATE1)) {
          util.message("请先输入评价信息!");
          return false;
        }
      } 
      if(util.isNotEmpty(this.data.searchList.RESPONSIBLE_LIST_1)){
        
        // 提请人评论 经办领导；提请人 登录
        if(this.data.status==10&&util.isEmpty(this.data.searchList.EVALUATE3)){
          util.message("请先输入评价信息!");
          return false;
        }
        
        //经办领导的评价 ; 经办领导登录 
        if(this.data.status==8&&util.isEmpty(this.data.searchList.EVALUATE5)){
          util.message("请先输入评价信息!");
          return false;
        }
      }
      
      let searchList = this.data.searchList;
      //  console.log("--处理完成:",searchList);
      let json = { status: this.data.status, title: "处理完成", searchList };
      this.passSubmit(json)
 
    },
    index_list(ref) {
      this.index_list = ref;
      //  console.log("联系人");

    },
    bindKeyInput(e) {
      let key = e.currentTarget.dataset.key;
      this.setData({
        [`${key}`]: e.detail.value,
      });
    },
    bindObjPickerChange(e) {
      // console.log(e.detail.value);
      let arrIndex = e.detail.value;
      let obj = this.data.objectArray[arrIndex];
      let tagValue = obj.name;
      this.setData({
        arrIndex,
        'Approver.tagValue': tagValue,
        'Approver.Position': obj.tag
      })
    },
    moreClick() {
      this.setData({
        showMore: true
      })
      // debugger
    },
    onReset(e) {
      // console.log(e);
      this.setData({
        redio_value: "1"
      })
      this.onPopupClose();
    },
    close() {
      this.onPopupClose();
    },
    onTagSubmit(e) {

    },
    //打开否决延期弹层
    openVetoYanqi(){
      this.setData({
        showVetoYanqi: true
      })
    },
    closeVetoYanqi(){
      this.setData({
        showVetoYanqi: false
      })
    },
    submitVetoYanqi(){

    },
    adjournPass(e) { // 提起延期
      let name = e.currentTarget.dataset.name;
      // 判断是否必填
      if (util.isEmpty(this.data.searchList.DELAY_TIME)) {
        util.message("请选择延期期效");
        return false;
      }
      else if (util.isEmpty(this.data.searchList.DELAY_INFO)) {
        util.message("请输入延期理由");
        return false;
      }
     // debugger
      // 否决
      if (name == "back"){
        if (util.isEmpty(this.data.COMMENT)) {
          util.message("请输入否决理由");
          return false;
        }
      }
      
      //同意延期
      if(name == "agree"){
        
        if (new Date(this.data.searchList.DELAY_TIME).valueOf() < new Date(util.times("ymd_hds")).valueOf()) {
          util.message("延期期效小于当前日期，请重新选择");
          return false;
        };
      }
       
      // ==========
      this.data.searchList.historyStatus = this.data.searchList.STATUS; // 存储历史状态
      let COMMENTS1 = this.data.COMMENT, COMMENTS2 = "";
      // 判断获取当前状态
      if (name == "refer") {
        if (this.data.searchList.RESPONSIBLE_LIST_1 == app.prototype.$SysUserName && (this.data.searchList.STATUS == 2 || this.data.searchList.STATUS == 24)) {
          this.data.searchList.STATUS = 25;
        } else {
          if (util.isNotEmpty(this.data.searchList.RESPONSIBLE_LIST_1) && util.isNotEmpty(this.data.searchList.RESPONSIBLE_LIST_2)) {
            this.data.searchList.STATUS = 21;
          } else if (util.isEmpty(this.data.searchList.RESPONSIBLE_LIST_1) && util.isNotEmpty(this.data.searchList.RESPONSIBLE_LIST_2)) {
            this.data.searchList.STATUS = 23;
          }
        }
      } else if (name == "agree") { 
        // 判断当前操作按钮是谁在使用
        this.data.searchList.STATUS = 26; //修改时间23-5-19,测试条件 经办人==提起人
        //  有领导负责人 且 状态为21、23则当前审批人为领导负责人
        // if (util.isNotEmpty(this.data.searchList.RESPONSIBLE_LIST_1) && this.data.searchList.STATUS == 23) {
        //   // 判断是否是越级审批
        //   app.prototype.$SysUserName == this.data.searchList.RESPONSIBLE_LIST_1 ? this.data.searchList.STATUS = 25 : this.data.searchList.STATUS = 26;
        // } else if (util.isEmpty(this.data.searchList.RESPONSIBLE_LIST_1) || (util.isNotEmpty(this.data.searchList.RESPONSIBLE_LIST_1) && this.data.searchList.STATUS == 25)) {
        //   // 无领导负责人，则当前审批人为总经理 或 有领导人，状态为25 则当前审批人为发起人;
        //   this.data.searchList.STATUS = 26;
        // };
        if (this.data.searchList.HISTORY_DELAY_TIME != this.data.searchList.DELAY_TIME) {
          COMMENTS1 = `更换延期时间：${this.data.searchList.HISTORY_DELAY_TIME} 更换为 ${this.data.searchList.DELAY_TIME}`;
          COMMENTS2 = `更换延期时间：${this.data.searchList.HISTORY_DELAY_TIME} 更换为 ${this.data.searchList.DELAY_TIME}`;
        }
      } else if (name == "back") {
        // 经办人
        this.data.searchList.STATUS = 24;  //修改时间23-5-19 测试条件 经办人==提起人
        // if (this.data.searchList.RESPONSIBLE_LIST_1 == app.prototype.$SysUserName) {
        //   this.data.searchList.STATUS = 22;
        // } else if (this.data.searchList.USER_NAME == app.prototype.$SysUserName) {
        //   this.data.searchList.STATUS = 24;
        // }
      }

      COMMENTS1 = util.insertStrSeat(COMMENTS1, COMMENTS1.indexOf(">") + 1, this.commentStatusName(this.data.searchList));
      COMMENTS2 = JSON.parse(JSON.stringify(COMMENTS1));
      //  debugger
      // return false;
      dd.showLoading({
        content: '数据提交中...',
      })
      this.commentSend(COMMENTS2, "Work").then(res => {
        this.commentSend(COMMENTS1, "WorkOrderDelay").then(res => {
          this.data.searchList.RESPONSIBLE_LIST_COPY_1 = "";
          this.data.searchList.RESPONSIBLE_LIST_COPY_2 = "";
          let list = {
            STATUS: this.data.searchList.STATUS,
            DELAY_TIME: this.data.searchList.DELAY_TIME,
            DELAY_INFO: this.data.searchList.DELAY_INFO,
            WORKORDER_ID: this.data.searchList.WORKORDER_ID
          };

          // 当前同意操作人为提请人的话
          if (name == "agree" && this.data.searchList.USER_NAME == app.prototype.$SysUserName) list.DEADLINE = this.data.searchList.DELAY_TIME;
          // debugger

          app.$post("/YhERP/WorkOrder/json/edit1", list).then(res => {
            if (res.is == 1) {
              util.messageSuccess("提交成功");
              
              try {
                this.onReloadFn();
                this.onTagReset();
                this.closeVetoYanqi();
              } catch (error) {
                console.log(error);
              }
              // this.adjournCancel();
            } else {
              util.message(res.data.msg);
            }
            //  this.adjournLoading = false;
          });
        });
      });
    },
    taskOpen(name) {
      dd.alert({
        content: "请前往pc端点击'递进任务'按钮进行操作"
      })
      // util.message("请前往pc端点击'递进任务'按钮进行操作");
      return false;

      // 引用上次内容
      let CONTENT = "", historyTitle = this.data.searchList.TITLE;

      if (this.data.searchList.TITLE.indexOf("递进任务") != -1) {
        historyTitle = this.data.searchList.TITLE;
        this.data.searchList.TITLE = this.data.searchList.TITLE.replace(`（递进任务${util.isNotEmpty(this.data.searchList.QUOTE_NUM) ? this.data.searchList.QUOTE_NUM + 1 : 2}）`, "");
      }

      let recursion = "";
      if (util.isNotEmpty(this.data.searchList.QUOTE_NUM)) recursion = `（递进任务${this.data.searchList.QUOTE_NUM + 1}）`;

      CONTENT = `${this.data.searchList.TITLE} ${this.data.searchList.DEADLINE} ${recursion}`;

      CONTENT = util.insertStr(CONTENT, "start", CONTENT.length + 10, "—");
      CONTENT = util.insertStr(CONTENT, "end", CONTENT.length + 10, "—");
      this.data.searchList.CONTENT = `<p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p>${CONTENT}</p><p>${this.data.searchList.CONTENT}</p>`;

      let list = {
        CONTENT: this.data.searchList.CONTENT,
        QUOTE_NUM: this.data.searchList.QUOTE_NUM,
        WORKORDER_ID: this.data.searchList.WORKORDER_ID,
        USER_CN_NAME: this.data.searchList.USER_CN_NAME
      };
      let searchList = this.data.searchList;
      // this.data.searchList = this.copySearchList;
      // this.copySearchList = JSON.parse(JSON.stringify(this.data.searchList));

      searchList.STATUS = 1;
      searchList.TITLE = "";
      searchList.CONTENT = list.CONTENT;
      searchList.QUOTE_NUM = list.QUOTE_NUM;
      searchList.historyTitle = historyTitle;
      searchList.QUOTE_ID = list.WORKORDER_ID;
      searchList.USER_CN_NAME = list.USER_CN_NAME;

      let title = name == "again" ? "递进任务" : "引用转派";
      let disabled = name == "again" ? false : true;
      this.setData({
        title, disabled, searchList
      })
      this.pids();
    },
    onCommentOpen(e) {
      let STATUS = e.currentTarget.dataset.parameter;
      this.setData({
        COMMENT: "",
        STATUS,
        showComment: true
      })
    },
    onCommentSubmmit(e) {
      //console.log(this.data.STATUS);
      if (util.isEmpty(this.data.COMMENT)) {
        util.message("请输入审批意见!");
        return false;
      }
      // console.log(e);
      this.pass(e)
    },
    //确认提请完成
    onComment2Submmit(e) {
      //console.log(this.data.STATUS);
      if (util.isEmpty(this.data.COMMENT)) {
        util.message("请输入审批意见!");
        return false;
      }
      // console.log(e);
      let searchList = this.data.searchList;
     
      let json = { status: this.data.status, title: this.data.title, searchList };
      this.passSubmit(json)
    },
    commentList(PID,TYPE_NAME,name){
      let data = {
        PID,
        TYPE_NAME,
        currentPage: 1,
        showCount: 10
      };
      let that = this;
      app.$post("/YhERP/articleread/json/ArticleList", data).then(res => {
        if (res.is == 1) {
          let list=res.data.dataList;
          this.setData({
            [`${name}`]:list
          });
          console.log("---延期评论:",list);
        }else{
          util.message(res.msg)
        }
      })
    },
    onTagReset(e) {
      this.onCloseTag();
      this.onPopupClose();
    },
    openFn(searchList) {
      this.initData(searchList);
    },
    initData(searchList) {
      // let searchList = this.props.searchList;
      // console.log(searchList);

      let btn_list = [];
      let btnlist = this.data.btnlist;
      searchList.isRevoke = true;//开启撤回功能

      let time="getTime:"+searchList.ADD_TIME+":"+(util.getDateByString(searchList.ADD_TIME).getTime() + 10800000)+" ---new Date"+new Date().getTime();
     // console.log(time);
    // dd.alert({
    //   content: time
    // });
      // searchList.ADD_TIME="2022-08-01 12:00:00"
      // 若小于提交三小时，关闭撤回
      if (util.getDateByString(searchList.ADD_TIME).getTime() + 10800000 < new Date().getTime()) {
        //util.message("isRevoke=false")
        searchList.isRevoke = false;
      };

      if (searchList.STATUS == 10 && searchList.USER_NAME == app.prototype.$SysUserName) {
        // btnlist.di_jing_btn_show = true;//递进任务
        let json = { btn_show: true, func: "taskOpen", name: "递进任务", clazz: "background-blue", parameter: "" };
        btn_list.push(json)
      }

      // 经办人-申请延期
      if (searchList.STATUS != 51 &&
        searchList.USER_NAME != searchList.RESPONSIBLE_LIST_2 &&
        (searchList.RESPONSIBLE_LIST_2 == app.prototype.$SysUserName && (searchList.STATUS == 3 || searchList.STATUS == 5 || searchList.STATUS == 7 || searchList.STATUS == 22 || searchList.STATUS == 24 || searchList.STATUS == 26 || searchList.STATUS == 31))
      ) {
        //  btnlist.di_jing_btn_show = true;//申请延期
        let json = { btn_show: true, func: "adjournOpen", name: "申请延期", clazz: "background-blue", parameter: "申请延期" };
        btn_list.push(json)
      }

      //经办领导RESPONSIBLE_LIST_1，经办人USER_NAME 延期审核
      // if (searchList.STATUS != 51 &&
      //   ((searchList.STATUS == 21 && (searchList.RESPONSIBLE_LIST_1 == app.prototype.$SysUserName || searchList.USER_NAME == app.prototype.$SysUserName)) ||
      //     (searchList.STATUS == 23 && (searchList.USER_NAME == app.prototype.$SysUserName || searchList.RESPONSIBLE_LIST_1 == app.prototype.$SysUserName)) ||
      //     (searchList.STATUS == 25 && searchList.USER_NAME == app.prototype.$SysUserName)))

      // 经办人USER_NAME 延期审核

      if((searchList.STATUS == 21 &&searchList.USER_NAME == app.prototype.$SysUserName)||(searchList.STATUS == 23 &&searchList.USER_NAME == app.prototype.$SysUserName)||(searchList.STATUS == 25 &&searchList.USER_NAME == app.prototype.$SysUserName)){
        let json = { btn_show: true, func: "adjournOpen", name: "延期审核", clazz: "background-blue", parameter: "延期审核" };
        btn_list.push(json)
      }

      if (searchList.STATUS != 51 &&
        ((searchList.STATUS == 21 && searchList.RESPONSIBLE_LIST_1 != app.prototype.$SysUserName && searchList.USER_NAME != app.prototype.$SysUserName) ||
          (searchList.STATUS == 22 && searchList.RESPONSIBLE_LIST_2 != app.prototype.$SysUserName) ||
          (searchList.STATUS == 23 && searchList.USER_NAME != app.prototype.$SysUserName && (searchList.RESPONSIBLE_LIST_1 == '' || searchList.RESPONSIBLE_LIST_1 == undefined)) ||
          (searchList.STATUS == 25 && searchList.USER_NAME != app.prototype.$SysUserName))) {
        //  btnlist.postpone_detail_btn_show = true;  //延期详情
        // let json = { btn_show: true, func: "adjournOpen", name: "延期详情", clazz: "background-blue", parameter: "延期详情" };
        // btn_list.push(json)
      }

      if (searchList.STATUS == 10 && searchList.RESPONSIBLE_LIST_1 == app.prototype.$SysUserName) {
        // btnlist.continue_next_btn_show = true;  //继续流转
        let json = { btn_show: true, func: "pass", name: "继续流转", clazz: "background-blue", parameter: `${searchList.STATUS}`, parameter2: "continue" };
        btn_list.push(json)
      }

      if (searchList.STATUS != 51 && searchList.STATUS == 2
        && searchList.RESPONSIBLE_LIST_1 == app.prototype.$SysUserName) {
        // btnlist.next_btn_show =true; //流转
        let json = { btn_show: true, func: "pass", name: "流转", clazz: "background-blue", parameter: `3`, parameter2: "" };
        btn_list.push(json)
      }

      if (searchList.STATUS != 51 &&
        searchList.USER_NAME != searchList.RESPONSIBLE_LIST_2 &&
        searchList.RESPONSIBLE_LIST_2 == app.prototype.$SysUserName &&
        (searchList.STATUS == 3 || searchList.STATUS == 5 || searchList.STATUS == 7 || searchList.STATUS == 22 || searchList.STATUS == 23 || searchList.STATUS == 24 || searchList.STATUS == 25 || searchList.STATUS == 26 || searchList.STATUS == 31)) {
        //提请完成
        let json = { btn_show: true, func: "pass", name: "提请完成", clazz: "background-blue", parameter: `4`, parameter2: "" };
        btn_list.push(json)
      }

      if (searchList.STATUS != 51 && searchList.STATUS == 4 && searchList.RESPONSIBLE_LIST_1 == app.prototype.$SysUserName
        && searchList.RESPONSIBLE_LIST_2 != '' ) {
        let json1 = { btn_show: true, func: "pass", name: "同意完成", clazz: "background-blue", parameter: `8`, parameter2: "" };

        //退回，不同意 5
        let json = { btn_show: true, func: "onCommentOpen", name: "退回，不同意", clazz: "background-red", parameter: `5`, parameter2: "" };
        btn_list.push(json1,json);
      }

      // 发起人操作------------
      // searchList.STATUS != 51
      //   && ((searchList.STATUS == 8 && searchList.USER_NAME == app.prototype.$SysUserName) || (searchList.STATUS == 4 && searchList.USER_NAME == app.prototype.$SysUserName) || (searchList.STATUS != 10 && searchList.USER_NAME == app.prototype.$SysUserName && searchList.RESPONSIBLE_LIST_2 == app.prototype.$SysUserName))
      if (searchList.STATUS != 51
        && ((searchList.STATUS == 8 && searchList.USER_NAME == app.prototype.$SysUserName)|| (searchList.STATUS != 10 && searchList.USER_NAME == app.prototype.$SysUserName && searchList.RESPONSIBLE_LIST_2 == app.prototype.$SysUserName)
        ||(searchList.STATUS == 4 &&searchList.USER_NAME == app.prototype.$SysUserName && util.isEmpty(searchList.RESPONSIBLE_LIST_1)) )) {
        //处理完成
        let json = { btn_show: true, func: "pass", name: "处理完成", clazz: "background-blue", parameter: `10`, parameter2: "" };
        btn_list.push(json);
      }
      
      // (searchList.STATUS == 4 && searchList.USER_NAME == app.prototype.$SysUserName) ||
      
      if (searchList.STATUS != 51 &&
        searchList.USER_NAME != searchList.RESPONSIBLE_LIST_2 &&
        ((searchList.STATUS == 8 && searchList.USER_NAME == app.prototype.$SysUserName) ||
          (searchList.STATUS != 10 && searchList.USER_NAME == app.prototype.$SysUserName && searchList.RESPONSIBLE_LIST_2 == app.prototype.$SysUserName)
          ||(searchList.STATUS == 4 &&searchList.USER_NAME == app.prototype.$SysUserName && util.isEmpty(searchList.RESPONSIBLE_LIST_1)))) {
        //退回，不同意 7
        let json = { btn_show: true, func: "onCommentOpen", name: "退回，不同意", clazz: "background-red", parameter: `7`, parameter2: "" };
        btn_list.push(json)
      }
      // ---------

      let  SysUserName=app.prototype.$SysUserName;
      
      if (searchList.isRevoke && searchList.BACK != 1 && searchList.STATUS != 10 && searchList.STATUS != 51 && searchList.USER_NAME == SysUserName) {
        //撤回
        let json = { btn_show: true, func: "recall", name: "撤回", clazz: "background-red", parameter: ``, parameter2: "" };
        btn_list.push(json)
      }
      //console.log("------searchList::",searchList);
      this.setData({
        btn_list, searchList, SearchList: searchList
      })
    },
    commentStatusName(item, name) {
      if (this.data.title == "递进任务" || this.data.title == "引用转派") {
        return `发起${this.data.title}联系单。\t
                期效时间：${item.DEADLINE}。\t
                <a class="commentTask">
                  <span>历史任务事项：</span>
                  <span style="border-bottom: 1px solid #606266;">${item.historyTitle}</span>
                </a>`; // 发起人
      }
      if (item.historyStatus == undefined && (item.STATUS == 2 || item.STATUS == 3)) {
        return `发起联系单。期效时间：${item.DEADLINE}`; // 发起人
      } else if ((item.historyStatus == 2 || item.historyStatus == 26 ||item.historyStatus == 31) && item.STATUS == 3) {
        let RESPONSIBLE_LIST_2 = [];

        if (util.isType(item.RESPONSIBLE_LIST_COPY_2) == "Object") {
          return "经办领导流转该联系单。";
        } else {
          for (let i in item.RESPONSIBLE_LIST_COPY_2) {
            RESPONSIBLE_LIST_2.push(item.RESPONSIBLE_LIST_COPY_2[i].NAME);
          };
          if (RESPONSIBLE_LIST_2.length != 0) {
            return `经办领导流转该联系单，流转人员：${RESPONSIBLE_LIST_2[0]}`;
          } else {
            return `经办领导流转该联系单。`;
          };
        };
      } else if ((item.historyStatus == 3 || item.historyStatus == 5 || item.historyStatus == 7 || item.historyStatus == 22 || item.historyStatus == 23 || item.historyStatus == 24 || item.historyStatus == 26|| item.historyStatus == 31) && item.STATUS == 4) {
        return "提请完成。"; // 负责人
      } else if ((item.historyStatus == 4||item.historyStatus == 31) && item.STATUS == 8) {
        return "同意完成。"; // 经办领导
      } else if ((item.historyStatus == 4||item.historyStatus == 31) && item.STATUS == 5) {
        return "经办领导否决完成。"; // 经办领导
      } else if ((item.historyStatus == 3 || item.historyStatus == 4 || item.historyStatus == 7 || item.historyStatus == 8 || item.historyStatus == 31) && item.STATUS == 10) {
        return "提请人同意完成。"; // 发起人
      } else if ((item.historyStatus == 3 || item.historyStatus == 4 || item.historyStatus == 7 || item.historyStatus == 8 || item.historyStatus == 31) && item.STATUS == 7) {
        return "提请人否决完成。"; // 发起人
      } else if ((item.historyStatus == 3 || item.historyStatus == 5 || item.historyStatus == 7 || item.historyStatus == 22 || item.historyStatus == 24 || item.historyStatus == 26|| item.historyStatus == 31) && (item.STATUS == 21 || item.STATUS == 23)) {
        let msg = `提请延期，延期期效：${item.DELAY_TIME}，`;
        if (util.isNotEmpty(this.data.searchList.DELAY_INFO)) {
          msg += `延期理由：${this.data.searchList.DELAY_INFO}。`
        }
        return msg;
      } else if ( (item.historyStatus == 23|| item.historyStatus == 31) && item.STATUS == 25) {
        return "经办领导同意延期。";
      } else if (name != "continue" && (item.historyStatus == 23|| item.historyStatus == 31) && (item.STATUS == 22 || item.STATUS == 23)) {
        return "经办领导否决延期。";
      } else if ((item.historyStatus == 21 || item.historyStatus == 23 || item.historyStatus == 25|| item.historyStatus == 31) && item.STATUS == 26) {
        return "提请人同意延期。";
      } else if ((item.historyStatus == 21 || item.historyStatus == 23 || item.historyStatus == 25|| item.historyStatus == 31) && item.STATUS == 24) {
        // 没有经办领导的话为提请人退回
        return "提请人否决延期。";
      } else if (item.historyStatus == 31 && item.STATUS == 4) {
        return "逾期后，提请完成。";
      } else if (item.historyStatus == 31 && (item.STATUS == 21 || item.STATUS == 23)) {
        return "逾期后，申请延期。";
      } else if ((item.historyStatus == 2 || item.historyStatus == 24 || item.historyStatus == 31) && item.STATUS == 25) { // 经办领导提请延期
        return "经办领导提请延期申请。";
      } else if (item.historyStatus == item.STATUS && item.RESPONSIBLE_LIST_1 == app.prototype.$SysUserName) {
        return `经办领导流转该联系单，流转人员：${this.data.searchList.RESPONSIBLE_2}`;
      };
    },
    passFn() {
      dd.confirm({
        title: '温馨提示',
        content: '是否确认进行通过?',
        confirmButtonText: '通过',
        cancelButtonText: '取消',
        success: (result) => {
          if (result.confirm) {
            this.passQuest();

          }
        },
      });
    },
    recall() { // 撤回

      dd.confirm({
        title: '提示',
        content: '确认撤回?',
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        success: (result) => {
          if (result.confirm) {
            dd.showLoading({
              content: '数据提交中...',
            })
            app.$post("/YhERP/WorkOrder/json/editUndo", { WORKORDER_ID: this.data.searchList.WORKORDER_ID }).then(res => {
              if (res.is == 1) {
                dd.hideLoading();
                util.messageSuccess("撤回成功");
                this.onReloadFn();
              } else {
                util.message(res.data.msg);
              }
            });
          }

        },
      });

    },
    adjournOpen(e) {//申请延期
      let parameter = e.currentTarget.dataset.parameter;
      // 避免提起人为自己，经办人为打开同意延期申请无法显示出数据
      let searchList = this.data.searchList;
      //控制延期 按钮显示
      let postpone_btn_list = JSON.parse(JSON.stringify(base_postpone_btn_list));


      if (searchList.RESPONSIBLE_LIST_2.indexOf(app.prototype.$SysUserName) == -1 && parameter != "申请延期") {
        searchList.DELAY_TIME = this.data.SearchList.DELAY_TIME;
      } else {
       //  searchList.DELAY_TIME = "";
      // searchList.DELAY_INFO="";
      }

      
      //经办人 打开申请延期的窗口进行 延期申请
      if (searchList.RESPONSIBLE_LIST_2.indexOf(app.prototype.$SysUserName) != -1 && parameter == "申请延期") {
        searchList.DELAY_TIME = "";
        searchList.DELAY_INFO=""; //经办人 打开申请延期的窗口 清空文本框上次输入的内容
        postpone_btn_list.comment_show=true;
        
        let PID=this.data.searchList.WORKORDER_ID+"WorkOrderDelay"
        this.commentList(PID,"WorkAuto","adjournCommonList")
      }
      
     // searchList.DELAY_INFO = this.data.SearchList.DELAY_INFO;
      // ================================
      let COMMENT = ""; // 清空评论情况
      
      //办理中 经办人 提起延期 清空上次填写内容
      
      if(searchList.STATUS == 3){
        searchList.DELAY_INFO="";
      }
      
      if((searchList.STATUS == 24||searchList.STATUS == 22)&&searchList.is_jingban_ren){
        searchList.DELAY_INFO="";
      }

      //提交 按钮
      if (((searchList.STATUS == 2 || searchList.STATUS == 7 || searchList.STATUS == 24 || searchList.STATUS == 26) && searchList.RESPONSIBLE_LIST_1 == app.prototype.$SysUserName) ||
        ((searchList.STATUS == 3 || searchList.STATUS == 5 || searchList.STATUS == 7 || searchList.STATUS == 22 || searchList.STATUS == 24 || searchList.STATUS == 26) && searchList.RESPONSIBLE_LIST_2 == app.prototype.$SysUserName)) {
        postpone_btn_list.submit_btn_show = true;
      }
      // 同意延期 按钮
      if ((searchList.STATUS == 21 && searchList.USER_NAME == app.prototype.$SysUserName) || (searchList.STATUS == 23 && searchList.USER_NAME == app.prototype.$SysUserName) || (searchList.STATUS == 25 && searchList.USER_NAME == app.prototype.$SysUserName)) {
        postpone_btn_list.agree_btn_show = true;
      }
      // 否决延期
      if ((searchList.STATUS == 21 && (searchList.RESPONSIBLE_LIST_1 == app.prototype.$SysUserName || searchList.USER_NAME == app.prototype.$SysUserName)) || (searchList.STATUS == 23 && (searchList.USER_NAME == app.prototype.$SysUserName || searchList.RESPONSIBLE_LIST_1 == app.prototype.$SysUserName)) || (searchList.STATUS == 25 && searchList.USER_NAME == app.prototype.$SysUserName)) {
        postpone_btn_list.veto_btn_show = true;
      }
      this.setData({
        "searchList.DELAY_TIME": searchList.DELAY_TIME,
        "searchList.DELAY_INFO": searchList.DELAY_INFO,
        COMMENT,
        postpone_btn_list
      })
      this.onOpenTag();

    },

    commentSend(Comment, TYPE_NAME, voluntarily) { // 评论
      let list = {
        TYPE_NAME,
        COMMENTS: encodeURI(Comment),
        PID: this.data.searchList.WORKORDER_ID + TYPE_NAME,
      };
      if(util.isEmpty(voluntarily)){
        list.TYPE_NAME="WorkAuto";
      }
      return app.$post("/YhERP/articleread/json/save/URLEncode", list).then(res => {
        if (res.is == 1) {
          // util.message("评论成功!")
          if (util.isNotEmpty(voluntarily)) {
            util.messageSuccess("发表成功");
          }
        } else {
          util.errorHint(res, this);
        }
      });
    },
    onPass(list) {
      // let RECEIVER = list, RECEIVERS = [];
      // for (let index = 0; index < list.length; index++) {
      //   let user_en_name = list[index];
      //   let user_cn_name = app.prototype.$USERNAME_MAP.get(user_en_name);
      //   if (util.isNotEmpty(user_cn_name)) {
      //     RECEIVERS.push(user_cn_name);
      //   };
      // }
      let searchList = this.data.searchList;
      searchList.RESPONSIBLE_LIST_2=list.join(",")
      let json = { status: this.data.status, title: this.data.title, searchList };
      this.passSubmit(json)
    },
    getDate(type) {
      const date = new Date();
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();

      if (type === 'start') {
        date.setDate(1); //获取这个月1号
        day = date.getDate();
      } else if (type === 'end') {
        day = date.getDate(); //当前天
      } else if (type === 'lastMonth') {
        if (month > 2) {
          month--;
        } else {
          month = 1;
        }
        date.setDate(1); //获取这个月1号
        day = date.getDate();
      };

      month = month > 9 ? month : '0' + month;
      day = day > 9 ? day : '0' + day;
      return `${year}-${month}-${day}`;
    },
    complexChoose(e) {
      let currentDate = this.data.searchList.DELAY_TIME;
      // if(this.data.searchList.is_leader){ //经办领导 延期审批时不能选择延期奇效时间
      //   return;
      // }
      let that = this;
      dd.datePicker({
        format: 'yyyy-MM-dd HH:mm:ss',
        currentDate,
        success: (res) => {
          try{
            let DELAY_TIME = res.date+":59";
            let now = new Date();

            let now_str= util.strDateFormat (now,"yyyy-MM-dd HH:mm:59") ;
            let now_date = util.getDateByString(now_str);

            //console.log("---DELAY_TIME:"+DELAY_TIME,"----str_date:",now_str);
            let choose_date = util.getDateByString(DELAY_TIME);

            if (choose_date <= now_date) {
              util.message("所选时间不能小于或等于当前时间!")
              return false;
            }
            that.setData({
              "searchList.DELAY_TIME": DELAY_TIME
            })
          }catch(e){
            console.log(e);
          }
          
        },
      });
    },
    onPopupClose() {
      this.setData({
        showComment: false,
        showComment2: false,
        showMore: false,
        showVetoYanqi:false
      });
    },
    onCloseTag() {
      this.setData({
        STATUS: "",
        COMMENT: "",
      //  "searchList.DELAY_INFO":"",
        showAdjourn: false,
      });
      this.closeVetoYanqi();
    },
    onShowComment2(){
      this.setData({
        showComment2: true,
        COMMENT:""
      })
    },
    cancel() {
      this.closeScorePopup();
      this.onCloseTag();
      this.onPopupClose();
      this.onReloadFn();
    },
    onOpenTag() {
      // console.log(this.data.searchList);
      // debugger
      this.setData({
        showAdjourn: true
      });
    },
    radioChange(e) {
      //console.log(e);
      this.setData({
        redio_value: e.detail.value
      })
    },
    addTag() {
      if (this.data.approvalApi.typeName == "gradually") {
        this.onOpenTag();
      } else {
        this.complexChoose();
      }
      // this.complexChoose();
    },
    rejectQuest() {
      let STATUS = 4;
      let data = this.props.approvalApi.apiApprovalAdminSubmit.data;
      data.STATUS = STATUS;
      this.approvalSubmit(STATUS, data);
    },
    passSubmit(e) {
      let status = e.status, name = e.title, searchList = e.searchList;
      if (util.isEmpty(searchList.RESPONSIBLE_LIST_2) && util.isEmpty(searchList.RESPONSIBLE_LIST_1)) {
        util.message("请选择经办领导或具体经办人");
        return false;
      }

      // 判断是否有填期效时间
      if (util.isEmpty(searchList.DEADLINE)) {
        util.message("请选择期效时间");
        return false;
      }

      // 判断新增时期效时间是否小于今天
      if (this.data.title == "新增" && new Date(searchList.DEADLINE).valueOf() <= new Date(util.times("currentDate")).valueOf()) {
        if (Number(new Date()) > Number(new Date(util.times("ymd") + " 18:00:00"))) {
          util.message("已今日期效提交时间，请选择其他日期进行提交");
          return false;
        }

        if (new Date(searchList.DEADLINE).valueOf() < new Date(util.times("currentDate")).valueOf()) {
          util.message("期效日期小于当前日期，请重新选择");
          return false;
        }
      }

      if (searchList.STATUS == 2 && (JSON.stringify(searchList.RESPONSIBLE_LIST_2) == "[]" || util.isEmpty(searchList.RESPONSIBLE_LIST_2))) {
        util.message("请选择流转人员");
        return false;
      }

      // if (status == 10 && this.data.searchList.USER_NAME == app.prototype.$SysUserName && this.$refs.rate1.currentValue == 0 && this.$refs.rate3.currentValue == 0) {
      //   let hint =  "请予评价后再提交";;
      //   // if (this.$route.query.type == "manage" && (app.prototype.$SysUserName == "huangyanjun" || app.prototype.$SysUserName == "yangrong" || app.prototype.$SysUserName == "chenchengwei" || app.prototype.$SysUserName == "SM")) {
      //   //   hint = "请进入录入处理-工作联系进行评价";
      //   // } else {
      //   // }
      //   util.message(hint);
      //   return false;
      // }
      // let step = 1;
      // this.$refs.el_form.validate((valid, item) => {
      //   for (let i in item) {
      //     if (step > 1) break;
      //     util.message(item[i][0].message);
      //     step++;
      //   }
      // });
      // if (step > 1) return false;

      if ((status == 5 || status == 7) && util.isEmpty(this.data.COMMENT)) {
        util.message("请填写讨论内容");
        return false;
      }

      searchList.TYPE = "Work";
      let api = this.data.title == "递进任务" || this.data.title == "引用转派" ? "/YhERP/WorkOrder/json/save1" : "/YhERP/WorkOrder/json/edit1";
      if ((searchList.STATUS == 2 || searchList.STATUS == 26) && searchList.RESPONSIBLE_LIST_1 == app.prototype.$SysUserName && util.isEmpty(this.data.searchList.RESPONSIBLE_LIST_2)) {
        util.message("请填写具体经办人");
        return false;
      }

      try { // 数组转字符串
        this.data.searchList.DUBLE_RESPONSIBLE_LIST_2 = "";
        // if (this.$route.query.urlName == "rules_Feedback") {
        //   if (util.isType(this.data.searchList.RESPONSIBLE_LIST_1) == "Array") {
        //     this.data.searchList.RESPONSIBLE_LIST_1 = this.data.searchList.RESPONSIBLE_LIST_1.join(",");
        //   }
        // }

        // 获取经办领导中文名
        if (util.isNotEmpty(searchList.RESPONSIBLE_LIST_1)) {
          searchList.RESPONSIBLE_1 = app.prototype.$USERNAME_MAP.get(searchList.RESPONSIBLE_LIST_1);
        }

        // 获取具体经办人
        if ((this.data.title == "递进任务" || this.data.title == "引用转派") && Array.isArray(searchList.RESPONSIBLE_LIST_2) && this.data.searchList.RESPONSIBLE_LIST_2.length > 1) { // 初次流转
          searchList.DoubleWork = "type1";
          searchList.DUBLE_RESPONSIBLE_LIST_2 = searchList.RESPONSIBLE_LIST_2.join(",");
        } else if ((this.data.title == "递进任务" || this.data.title == '引用转派') && Array.isArray(searchList.RESPONSIBLE_LIST_2) && this.data.searchList.RESPONSIBLE_LIST_2.length > 1) { // 继续流转
          searchList.DoubleWork = "type2";
          searchList.DUBLE_RESPONSIBLE_LIST_2 = searchList.RESPONSIBLE_LIST_2.join(",");
        } else {
          if (util.isType(searchList.RESPONSIBLE_LIST_2) == "String") {
            searchList.RESPONSIBLE_2 = app.prototype.$USERNAME_MAP.get(searchList.RESPONSIBLE_LIST_2) || "";
            searchList.RESPONSIBLE_LIST_2 = searchList.RESPONSIBLE_LIST_2 || "";
          } else {
            for (let i in searchList.RESPONSIBLE_LIST_2) {
              searchList.RESPONSIBLE_2 = app.prototype.$USERNAME_MAP.get(searchList.RESPONSIBLE_LIST_2[i]) || "";
              searchList.RESPONSIBLE_LIST_2 = searchList.RESPONSIBLE_LIST_2[i] || "";
            }
          }
        }
      } catch (e) {
        console.log(e);
      }

      // 绑定协助人数据
      try {
        searchList.RELEVANT_PERSONNEL_11 = [];
        // 获取协助人中文名字
        for (let i in searchList.RELEVANT_PERSONNEL_LIST_11) {
          searchList.RELEVANT_PERSONNEL_11.push(app.prototype.$USERNAME_MAP.get(searchList.RELEVANT_PERSONNEL_LIST_11[i]));
        }
        // 数组转字符串
        searchList.RELEVANT_PERSONNEL_1 = searchList.RELEVANT_PERSONNEL_11.join(",");
        searchList.RELEVANT_PERSONNEL_LIST_1 = searchList.RELEVANT_PERSONNEL_LIST_11.join(",");
      } catch (e) {
        console.log(e);
      }

      searchList.historyStatus = searchList.STATUS; // 存储本次详情的状态
      searchList.STATUS = status; // 替换状态

      // 系统默认状态名字 + 自输内容
      let COMMENT = util.insertStrSeat(this.data.COMMENT, this.data.COMMENT.indexOf(">") + 1, this.commentStatusName(searchList, name));
      let list = { STATUS: searchList.STATUS, WORKORDER_ID: searchList.WORKORDER_ID };
      if (status == 3 && this.data.title != "递进任务") {
        list.RESPONSIBLE_2 = searchList.RESPONSIBLE_2;
        list.RESPONSIBLE_LIST_2 = searchList.RESPONSIBLE_LIST_2.length <= 2 ? searchList.DUBLE_RESPONSIBLE_LIST_2 : searchList.RESPONSIBLE_LIST_2;
      } else if (this.data.title != "递进任务" && this.data.title != "引用转派") {
        list.STATUS = searchList.STATUS;
        list.WORKORDER_ID = searchList.WORKORDER_ID;
      } else {
        list = searchList;
      }
      list.TYPE = "Work";
      // 判断是否是继续流转
      if (searchList.DoubleWork == "type2") {
        list.DoubleWork = "type2";
        list.RESPONSIBLE_LIST_2 = [];
        list.DUBLE_RESPONSIBLE_LIST_2 = searchList.DUBLE_RESPONSIBLE_LIST_2;
      }

      if (this.data.title == "递进任务") list.TITLE = `${searchList.TITLE} （递进任务${util.isNotEmpty(searchList.QUOTE_NUM) ? searchList.QUOTE_NUM += 2 : 2}）`;
      // 避免报错 Cyclic object value
      list.RESPONSIBLE_LIST_COPY_1 = "";
      list.RESPONSIBLE_LIST_COPY_2 = "";
      list.EVALUATE1 = searchList.EVALUATE1;
      list.EVALUATE3 = searchList.EVALUATE3;
      if(this.data.status==8){
        list.EVALUATE5 = searchList.EVALUATE5;

      }
      if(status == 7){
        list.EVALUATE5=0;
      }          
      // ===========================
      
      // this.loading = true;
      // 确认完成与确认搁置的情况下提交需确认
      let that = this;
      dd.showLoading({
        content: '数据提交中...',
      })
      
      app.$post(api, list).then(res => {
      
        if (res.is == 1) {
          // this.copyApi = "";
          try {
           // console.log("--commit 1");
            dd.showToast({
              content: "提交成功",
              type: "success",
              duration: 1500,
              success: function (params) {
                
              }
            });
            if(util.isNotEmpty(COMMENT)){
              this.commentSend(COMMENT, "Work").then(res => {
                COMMENT = "";
                that.setData({
                  COMMENT
                })
                that.cancel();
                // this.loading = false;
              });
            }
            
          } catch (error) {
            console.log(error);
          }
        } else {
          util.message(res.data.msg);
        }

        // 将提议建议状态置位办理完成
        if (util.isNotEmpty(list.RESPONSIBLE_LIST_3)) {
          let STATUS = list.STATUS == 10 && util.isNotEmpty(list.RESPONSIBLE_LIST_3) ? 3 : 2;
          let p={ ARTICLE_ID: list.RESPONSIBLE_LIST_3, STATUS }
          if(list.STATUS != 10){
            p.RESPONSIBLE = JSON.stringify([list.RESPONSIBLE_LIST_2]);
            p.TRANSFER = JSON.stringify([list.RESPONSIBLE_LIST_1]);
            p.RELEVANT = JSON.stringify([list.RESPONSIBLE_LIST_11]);
          }
          app.$post("/YhERP/article/editJson", p).then(res => {
          });
        }
      });
    
    },
    pass(e) {
      let status = e.currentTarget.dataset.parameter, name = e.currentTarget.dataset.parameter2, title = e.currentTarget.dataset.title;

      let searchList = this.data.searchList;
      let json = { status, title, searchList };
      this.setData({
        status,title
      })
      dd.confirm({
        title: '提示',
        content: `是否确认${title}?`,
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        success: (result) => {
          if (result.confirm) {
            //debugger
            if(status==3){
              //递进任务
              this.setData({
                "Approver.Approver":app.prototype.$SysUserName
              })
              this.index_list.openFn()
            }else if(status == 10||status == 8) {
              //处理完成进行评分操作
              this.openScorePopup();
            }else if(status == 4) {
              //提请完成 进行评论
              this.onShowComment2();
            } else {
              this.passSubmit(json)
            }

          }
        },
      });
    },
    cleanScorePopup(){
      this.setData({
        ceteImgList1: util.copy(baseImgList),
        ceteImgList2: util.copy(baseImgList),
        score1: "",
        score2: ""
      })
    },
    openScorePopup() {
      this.setData({
        showScore: true
      });
      this.cleanScorePopup();

    //  console.log("---ceteImgList1",this.data.ceteImgList1);
    },
    closeScorePopup() {
      this.setData({
        score1: "",
        score2: "",
        showScore: false
      })
    },
    pids() {
      app.$post("/YhERP/WorkOrder/json/goAdd").then(res => {
        if (res.is == 1) {
          if (this.data.title == "递进任务" || this.data.title == "引用转派") {
            //this.data.searchList.WORKORDER_ID = res.data.WORKORDER_ID;
            this.setData({
              "searchList.WORKORDER_ID": res.data.WORKORDER_ID
            })
          } else {
            // this.PID = res.data.WORKORDER_ID;
          };
        } else {
          util.message(res.data.msg);
          //util.errorHint(res, this);
        };
      });
    },
    onReloadFn() {
      dd.hideLoading();
      this.props.onReloadFn()
    }
  },
});
